You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Proposal: QGEMeans, mini-batch e-means with SymphonyQG assignment - #261
QGEMeans, mini-batch e-means with SymphonyQG assignment
Adds rabitqlib::qgemeans::QGEMeans (C++) and rabitqlib.QGEMeans (Python). It is the e-means recipe (arXiv:2611.09501, Algorithm 1, with the constants from Faiss contrib/e_means), with each mini-batch assigned through a SymphonyQG graph over the current centroids. This is a new class; QGKMeans and RaBitQKMeans keep their current behaviour.
Training: a seeded shuffle each epoch, then fixed-size mini-batches; the batch size follows the batch-size law. Before every mini-batch the raw-vector centroid graph is rebuilt and searched top-1. Centroids take an EMA mass-weighted step under the step law with a cosine schedule. Every five mini-batches, centroids with little mass are revived by splitting heavy ones. The last epoch's means become the final centroids.
API: the same as the other clustering classes: train, train_centroids, assign, centroids, assignments, distances, iteration_stats (one entry per epoch) and final_obj. final_assignment is 'approximate' by default, or 'exact'. A failed train keeps the previous results, and results are identical for any thread count.
Parameters:epochs=8, batch_size=0 (use the batch-size law), max_degree=32, ef_construction=240, ef_search=16, graph_build_iterations=1, seed, num_threads, verbose. Python uses the index-style names from the start, so there are no deprecated aliases.
Shared code: parameter checks, the trained-model assign front end and the final-assignment dispatch now live in clustering::detail, and the centroid-graph checks in qgkmeans::detail. All three classes use them, and the existing error messages are unchanged. QGAssigner::search_points takes an optional row index list, so mini-batches are searched in place without copying them.
Also included: a sample (bin/qgemeans), C++ and Python tests, the type stub, and docs in clustering.md.
Benchmark
GIST1M, k = 4096, seed 42, Xeon Gold 6418H, GCC 14 -march=native, 8 threads pinned to physical cores 4–11. Two interleaved runs of each.
Method
Train time
Exact WCSS
Recall@10
Imbalance
QGKMeans, 25 iterations
33.8 / 34.0 s
1.03471e6
0.8159
1.413
QGEMeans, 8 epochs
20.7 / 20.7 s (1.64× faster)
1.03166e6 (−0.3%)
0.8185
1.257
QGEMeans reproduces the standalone prototype bit for bit; its time was 21.0 s.
About a third of QGEMeans training (7.0 of 21.0 s) is rebuilding the centroid graph.
Next: quantized graph build
I'm working on a quantized (8-bit, AVX-512 VNNI) SymphonyQG graph build. On a full GIST1M index it cuts build time from 31.8 s to 19.4 s at 48 threads, and from 662 s to 407 s on one thread, with recall within noise. QGEMeans rebuilds its centroid graph before every mini-batch, so a faster build should lower its total time further. That will come as a follow-up PR once this one is merged.
Checks
clang-format and full clang-tidy.
The C++ suite: 518 tests.
The installed CMake consumer test.
The Python suite: 1227 tests, plus the mypy editor checks.
mkdocs build --strict.
Not run: Pyright, which needs Node 24; CI runs it.
Thanks for the proposal! 0.9 is in its final release steps, so we're holding new features until it lands on main. Once it does, could you rebase this branch onto the new main? It starts from main before the 0.9 work, and a trial merge with dev/0.9 conflicts in seven files. The main one is qgkmeans.hpp: on dev/0.9, QGAssigner rejects METRIC_COSINE (#256), the QGKMeans parameters are renamed (#233), and the k-means coordinate bound changed (#249). So the moved qg_assigner.hpp needs to start from the 0.9 version.
After the rebase we'll review it in full. In case you want to prepare, we'll check:
that QGKMeans and RaBitQKMeans give the same results as before the shared-helper refactor;
the benchmark on a second dataset, with the exact commands;
the e-means references (the paper and the Faiss contrib code) for the constants you use.
0.9.0 is now on main (v0.9.0). Could you rebase this branch onto the current main when you have time? The notes in my previous comment still apply, especially starting the moved qg_assigner.hpp from the 0.9 version. Then we'll do the full review.
This branch has not been deployed
No deployments
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
QGEMeans, mini-batch e-means with SymphonyQG assignment
Adds
rabitqlib::qgemeans::QGEMeans(C++) andrabitqlib.QGEMeans(Python). It is the e-means recipe (arXiv:2611.09501, Algorithm 1, with the constants from Faisscontrib/e_means), with each mini-batch assigned through a SymphonyQG graph over the current centroids. This is a new class; QGKMeans and RaBitQKMeans keep their current behaviour.train,train_centroids,assign,centroids,assignments,distances,iteration_stats(one entry per epoch) andfinal_obj.final_assignmentis'approximate'by default, or'exact'. A failedtrainkeeps the previous results, and results are identical for any thread count.epochs=8,batch_size=0(use the batch-size law),max_degree=32,ef_construction=240,ef_search=16,graph_build_iterations=1,seed,num_threads,verbose. Python uses the index-style names from the start, so there are no deprecated aliases.assignfront end and the final-assignment dispatch now live inclustering::detail, and the centroid-graph checks inqgkmeans::detail. All three classes use them, and the existing error messages are unchanged.QGAssigner::search_pointstakes an optional row index list, so mini-batches are searched in place without copying them.bin/qgemeans), C++ and Python tests, the type stub, and docs inclustering.md.Benchmark
GIST1M, k = 4096, seed 42, Xeon Gold 6418H, GCC 14
-march=native, 8 threads pinned to physical cores 4–11. Two interleaved runs of each.Next: quantized graph build
I'm working on a quantized (8-bit, AVX-512 VNNI) SymphonyQG graph build. On a full GIST1M index it cuts build time from 31.8 s to 19.4 s at 48 threads, and from 662 s to 407 s on one thread, with recall within noise. QGEMeans rebuilds its centroid graph before every mini-batch, so a faster build should lower its total time further. That will come as a follow-up PR once this one is merged.
Checks
mkdocs build --strict.🤖 Generated with Claude Code